﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using System.Threading;

namespace PhotoViewerLib
{
    // Represent a photo album
    public class Category
    {
        public List<Photo> photos { get; set; }
        public string name { get; set; }
        public int uid { get; set; }


        public Category(string name) // Constructor used by the program
        {
            this.name = name;
            this.photos = new List<Photo>();
        }

        public Category(DataRow dr) // Constructor used by the db
        {
            Object[] reader = dr.ItemArray;
            this.uid = Convert.ToInt32(dr[0]);
            this.name = (string)dr[1];
            this.photos = new List<Photo>();

            // The operation might take a while so we launch a thread
            ThreadStart datas = new ThreadStart(retrievePhotos);
            Thread thread = new Thread(datas);
            thread.Start();
        }


        public void retrievePhotos()
        {
            this.photos = Database.getPhotosForCategory(this);
        }

        public Category()
        {
            this.photos = new List<Photo>();
        }

        public void addPhoto(Photo p) 
        {
            this.photos.Add(p);
        }


        public void removePhoto(Photo p)
        {
            this.photos.Remove(p);
        }
    }
}
